package org.example.service.Listener;

import org.example.service.EmailService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageListener {
    @Autowired
    private EmailService emailService;

    //    定义指定监听的消息队列的名称
    @RabbitListener(queues = "direct_queue")
    public void receive(String id){
        System.out.println("已完成短信发送业务(rabbitmq direct)，id："+id);
        //监听到 direct_queue中有信息，就调用邮件接口发送邮件
        emailService.sendSimpleEmail(
                "3082311852@qq.com",
                "支付成功",
                "您的订单已支付成功，订单号为："+id
        );
    }

}

